package Model;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import Events.Recurrence;
import Events.Reminder;

public class DAORecuRemiWriter {
	private final String DIRECTION = "docs\\recuremain\\";
	private final String EXTENTION = ".rct";
	private final String EXTENTION2 = ".rmt";
	private DAOEventToFile dao;
	public DAORecuRemiWriter(DAOEventToFile daoEventToFile)
	{
		dao = daoEventToFile;
	}
	public boolean saveRecuminder(Object rec, int idob, int type)
	{
		ObjectOutputStream ob;
		try {
			File f = new File(DIRECTION+idob+(type==0?EXTENTION:EXTENTION2));
			ob = new ObjectOutputStream(new FileOutputStream(f));
			ob.writeObject(rec);
			ob.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return false;
	}
	public Object readRecuminder(int idob, int type)
	{
		Object ob = null;
		ObjectInputStream in;
		try {
			in = new ObjectInputStream(new FileInputStream(new File(DIRECTION+idob+(type==0?EXTENTION:EXTENTION2))));
			ob = in.readObject();
			in.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return ob;
	}
}
